package com.yfp.client.controller;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.yfp.client.annotation.AnonymousAccess;
import com.yfp.client.domain.vo.LotteryRecordVO;
import com.yfp.client.domain.vo.LotteryVO;
import com.yfp.client.service.LotteryRecordsService;
import com.yfp.common.core.domain.R;
import com.yfp.common.core.web.controller.BaseController;
import com.yfp.common.core.web.page.TableDataInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 *
 * @version 1.0
 * @date 2025-01-03 9:49
 */
@RestController
@RequestMapping("/client/lottery")
@Tag(name = "抽奖")
public class LotteryController extends BaseController {

    @Resource
    private LotteryRecordsService lotteryRecordsService;


    @AnonymousAccess
    @GetMapping("/prizeList")
    @Operation(summary = "抽奖页")
    public R<LotteryVO> prizeList(@RequestParam("cityName") String cityName) {
        return R.ok(lotteryRecordsService.prizeList(cityName));
    }

    @AnonymousAccess
    @PostMapping("/lotteryRecord")
    @Operation(summary = "抽奖记录")
    public R<TableDataInfo<LotteryRecordVO>> lotteryRecord(@RequestParam("lotteryId") Long lotteryId, @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @Param("getTime") Date getTime) {
        startPage();
        List<LotteryRecordVO> list = lotteryRecordsService.lotteryRecord(lotteryId,getTime);
        TableDataInfo dataTable = getDataTable(list);
        return R.ok(dataTable);
    }


    @AnonymousAccess
    @PostMapping()
    @Operation(summary = "抽奖")
    private R<LotteryRecordVO> lottery(@RequestParam("lotteryId") Long lotteryId){
        return R.ok(lotteryRecordsService.lottery(lotteryId));
    }


}
